home *** CD-ROM | disk | FTP | other *** search
- /*
-
- CmyDataFile.c
-
- this file adds a method to the standard definition. It uses some code
- borrowed from another project to do it.
- */
-
- #include "MessageDefines.h"
- #include "CmyDataFile.h"
-
- /* needed for the code module picked up from another project */
- typedef short WORD ;
- typedef char CHAR;
-
- long ReadaLine(WORD refNum,CHAR *tempString,WORD maxChars) ;
- #define NIL 0L
- static
- union
- {
- HParamBlockRec dfParameterBlock; /* our parameter block for private use */
- CInfoPBRec dirPBBlock;
- }p;
-
- /*:...................................................................................*/
- long ReadaLine(WORD refNum,CHAR *tempString,WORD maxChars)
- /* WORD refNum; /* Mac file reference number*/
- /*CHAR *tempString; /* where to store the data */
- /* WORD maxChars; /* maximum number of characters to read for this line */
- /*
- Name: Wade Maxfield
- Date: Feb 21, 1989
- Notes:
- Modification History:
- 11/25/89 -- here we mix objects and standard c code.
- */
- {
- WORD error;
- WORD stringCount;
-
-
- /*
- PBGetFPos (paramBlock: ParmBlkPtr; async: BOOLEAN) : OSErr;
-
- Trap macro _GetFPos
-
- Parameter block
- —> 12 ioCompletion pointer
- <— 16 ioResult word
- —> 24 ioRefNum word
- <— 36 ioReqCount long word
- <— 40 ioActCount long word
- <— 44 ioPosMode word
- <— 46 ioPosOffset long word
- */
- p.dfParameterBlock.fileParam.ioCompletion = NIL;
- p.dfParameterBlock.ioParam.ioRefNum = refNum;
- error = PBGetFPos (&p.dfParameterBlock,FALSE ) ;/* false = synchronously */
- if (error != noErr)
- return(error);
-
- /*PBRead (paramBlock: ParmBlkPtr; async: BOOLEAN) : OSErr;
- Trap macro _Read
- Parameter block
- --> 12 ioCompletion pointer
- <-- 16 ioResult word
- --> 24 ioRefNum word
- --> 32 ioBuffer pointer
- --> 36 ioReqCount long word
- <-- 40 ioActCount long word
- --> 44 ioPosMode word
- <-> 46 ioPosOffset long word
- */
- p.dfParameterBlock.ioParam.ioBuffer = tempString;
- p.dfParameterBlock.ioParam.ioReqCount =maxChars ;
- /* 0d is cr, $80 is newline mode */
- p.dfParameterBlock.ioParam.ioPosMode = fsAtMark+0x0D80;/* from present counter */
-
- error = PBRead (&p.dfParameterBlock,FALSE ) ;/* false = synchronously */
-
- if (p.dfParameterBlock.ioParam.ioActCount)
- stringCount =p.dfParameterBlock.ioParam.ioActCount-1;
- else
- stringCount = 0;
-
-
- /* all characters exhausted */
- if ( (error == eofErr && stringCount == 0 ) ||
- (error != noErr && error != eofErr) )
- return(error);
-
- if ( tempString[stringCount] == '\r')
- tempString[++stringCount]=0; /* delimit string */
- else
- tempString[++stringCount] = 0;
-
- return(stringCount);
-
- }
-
- /* now the methods */
-
- /* ................................................................... */
- void CmyDataFile::ImyDataFile(void)
- /*
- Name: Wade Maxfield
- Date: November 25, 1989
- Notes:
- initalize this object
- Modification History:
- */
- {
-
- /* call the superclass function */
- CDataFile::IDataFile();
- }
-
- /* ................................................................... */
- OSErr CmyDataFile::ReadLine(Ptr buffer, long howMuch, long *bytesRead)
- /*
- Name: Wade Maxfield
- Date: November 25, 1989
- Notes:
- read a line from the file into the buffer, stopping at carriage return
- return an ACK or a NAK
- Modification History:
- */
- {
- long returnValue;
-
- returnValue = ReadaLine(refNum,buffer, howMuch);
-
- if (returnValue < 0 )
- {
- *bytesRead = 0;
- return(NAK);
- }
- else
- {
- *bytesRead = returnValue;
- return(ACK);
- }
- }
-
-
-